package net.zjitc.servlet.second;

import net.zjitc.domain.Category;
import net.zjitc.domain.CategorySecond;
import net.zjitc.service.CategoryService;
import net.zjitc.service.SecondService;
import net.zjitc.service.impl.CategoryServiceImpl;
import net.zjitc.service.impl.SecondServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/**
 * 2 * @Author: 洪瑶
 * 3 * @Date: 2018/10/31 19:42
 * 4
 */
@WebServlet(name = "ModifyUIServlet",urlPatterns = "/modifyuiServlet")
public class ModifyUIServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        CategoryService service = new CategoryServiceImpl();
        SecondService secondService = new SecondServiceImpl();
        CategorySecond second = null;
        String csid = request.getParameter("csid");
        int id = Integer.parseInt(csid);
        try {
            second = secondService.findBy(id);
            request.setAttribute("second",second);
            List<Category> all = service.findAll();
            request.setAttribute("list",all);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("common/categorysecond/modify.jsp").forward(request,response);
    }
}
